package com.sky.mapper;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    void save(Orders orders);

    // 根据订单号查询
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    // 修改订单信息
    void update(Orders orders);

    List<Orders> findList(OrdersPageQueryDTO dto);
    @Select("select * from orders where id=#{id}")
    Orders findById(Long id);

    @Select("select count(*) from orders where status=#{status}")
    Integer orderByStatus(Integer status);
    @Select("select * from orders where status=#{status} and order_time<#{time}")
    List<Orders> findTimeOutOrder(Integer status, LocalDateTime time);

    @Select("select ifnull(sum(amount),0) from orders where status=#{status} and date(order_time)=#{date}")
    Double findStatusAndTime(Integer status, LocalDate date);

    Integer findStatusAndDate(Integer status, LocalDate date);

    List<Map<String, Object>> findSaleTop10(LocalDate begin, LocalDate end);
    @Select("select count(*) allOrders,sum(status=6) cancelledOrders," +
            "sum(status=5) completedOrders,sum(status=3) deliveredOrders," +
            "sum(status=2) waitingOrders from orders where date(order_time)=#{date}")
    OrderOverViewVO overviewOrders(LocalDate date);
}
